package com.zhaofujun.filequeue;

import java.util.concurrent.atomic.AtomicLong;

public class ReadNums {

    public int SIZE = 16;
    private final AtomicLong[] nums = new AtomicLong[SIZE];

    public ReadNums(long[] nums) {
        for (int i = 0; i < SIZE; i++) {
            this.nums[i] = new AtomicLong(nums[i]);
        }
    }

    public long[] getNums() {
        long[] positions = new long[SIZE];
        for (int i = 0; i < SIZE; i++) {
            positions[i] = this.nums[i].get();
        }
        return positions;
    }

    public boolean compareAndSet(int no, long expect) {
        return nums[no].compareAndSet(expect, expect + 1);
    }

    public long get(int no) {
        return nums[no].get();
    }
}
